package com.zlx.store.order.tunnel;

import com.zlx.store.common.constant.SecurityConstant;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class Tunnel {
    /**
     * 订单的付款队列，将创建好的订单发给支付宝
     * @return
     */
    @Bean
    public TopicExchange topicExchange() {
        return new TopicExchange("orderPayExchange", true, false);
    }

    @Bean
    public Queue oderCreateQueue() {
        return new Queue("orderPayQueue", true);
    }

    @Bean
    public Binding topicBinding(){
        return BindingBuilder.bind(oderCreateQueue())
                .to(topicExchange())
                .with("orderPay");
    }
    /**
     * 付款的延迟确认队列,用于写入数据库
     */
    @Bean
    public DirectExchange orderCheckExchange() {
        return new DirectExchange("order_check_queue", true, false);
    }

    @Bean
    public Queue orderCheckQueue() {
        return new Queue("order_check_exchange", true);
    }

    @Bean
    public Binding Binding(){
        return BindingBuilder.bind((oderCreateQueue()))
                .to(orderCheckExchange())
                .with("orderCheck");
    }
    @Bean
    public DirectExchange DelayExchange() {
        return new DirectExchange("mq_dlx_queue", true, false);
    }

    @Bean
    public Queue DelayQueue() {
        return new Queue("mq_dlx_exchange", true);
    }

    @Bean
    public Binding delayBinding(){
        return BindingBuilder.bind(DelayQueue())
                .to(DelayExchange())
                .with("mq_dlx_routing_key");
    }
}
